package org.study.tk.boot.mappercustome;

import tk.mybatis.mapper.additional.idlist.IdListMapper;
import tk.mybatis.mapper.additional.insert.InsertListMapper;
import tk.mybatis.mapper.common.*;

/**
 * 自己个性化的 Mapper
 *
 * @author Administrator
 */
public interface CommonMapper<T, PK> extends
        Mapper<T>,
        InsertListMapper<T>,
        IdsMapper<T>,
        IdListMapper<T, PK>,
        ConditionMapper<T>,
        BatchUpdateMapper {
    /**
     * 方法功能描述
     *
     * @param t
     * @return int
     */
    default int deleteWithVersion(T t) {
        int result = delete(t);
        if (result == 0) {
            throw new RuntimeException("删除失败!");
        }
        return result;
    }

    /**
     * 方法功能描述
     *
     * @param t
     * @return int
     */
    default int deleteByPrimaryKeyWithVersion(T t) {
        int result = deleteByPrimaryKey(t);
        if (result == 0) {
            throw new RuntimeException("删除失败!");
        }
        return result;
    }

    /**
     * 方法功能描述
     *
     * @param t
     * @return int
     */
    default int updateByPrimaryKeyWithVersion(T t) {
        int result = updateByPrimaryKey(t);
        if (result == 0) {
            throw new RuntimeException("更新失败!");
        }
        return result;
    }

    /**
     * 方法功能描述
     *
     * @param t
     * @return int
     */
    default int updateByPrimaryKeySelectiveWithVersion(T t) {
        int result = updateByPrimaryKeySelective(t);
        if (result == 0) {
            throw new RuntimeException("更新失败!");
        }
        return result;
    }
}
